//
//  CRProfileTableViewCell.m
//  CRChatRoom
//
//  Created by CuiFengshuai on 15/11/19.
//  Copyright © 2015年 SecondGroup. All rights reserved.
//

#import "CRProfileTableViewCell.h"


#define kDefaultTitleFont 16
#define kDefaultDetailFont 14
@interface CRProfileTableViewCell ()


@end

@implementation CRProfileTableViewCell

+ (instancetype)cellWithTableView:(UITableView *)tableView {
    static NSString *ID = @"status";
    CRProfileTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (!cell) {
        cell = [[CRProfileTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self setupSubViews];
    }
    return self;
}

- (void)setupSubViews {
    UILabel *titleLabel = [[UILabel alloc] init];
    [titleLabel setTextColor:[UIColor whiteColor]];
    [titleLabel setFont:[UIFont systemFontOfSize:kDefaultTitleFont]];
    [titleLabel setTextAlignment:NSTextAlignmentCenter];
    [self.contentView addSubview:titleLabel];
    self.titleLabel = titleLabel;
    
    UILabel *detailLabel = [[UILabel alloc] init];
    [detailLabel setTextColor:[UIColor whiteColor]];
    [detailLabel setFont:[UIFont systemFontOfSize:kDefaultDetailFont]];
    [detailLabel setTextAlignment:NSTextAlignmentCenter];
    [self.contentView addSubview:detailLabel];
    self.detailLabel = detailLabel;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    CGFloat titleX = 10;
    CGFloat titleY = 5;
    CGFloat titleW = 80;
    CGFloat titleH = 30;
    self.titleLabel.frame = CGRectMake(titleX, titleY, titleW, titleH);
    
    CGFloat detailX = CGRectGetMaxX(self.titleLabel.frame) + 15;
    CGFloat detailY = titleY;
    CGFloat detailW = self.width - detailX - 10;
    CGFloat detailH = titleH;
    self.detailLabel.frame = CGRectMake(detailX, detailY, detailW, detailH);
}

- (void)setFrame:(CGRect)frame {
    frame.origin.x = 20;
    frame.size.width -= 40;
    
    [super setFrame:frame];
}

- (void)setBackgroundColor:(UIColor *)backgroundColor {
    
    backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
    [super setBackgroundColor:backgroundColor];
}

@end
